package com.evildog.workspace.system.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.system.application.bo.DictTypePageBO;
import com.evildog.workspace.system.application.convert.DictTypeConvert;
import com.evildog.workspace.system.application.model.DictTypePageParam;
import com.evildog.workspace.system.application.model.DictTypeParam;
import com.evildog.workspace.system.application.service.DictTypeService;
import com.evildog.workspace.system.application.vo.DictTypePageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * dictType Controller
    字典表
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/dict-types")
@AllArgsConstructor
@Api(tags = "dictType相关接口")
public class DictTypeController {

    private DictTypeService dictTypeService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody @Validated DictTypeParam dictTypeParam) {
        return ResultGenerator.status(dictTypeService.save(DictTypeConvert.INSTANCE.convert(dictTypeParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(dictTypeService.removeById(id));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody DictTypeParam dictTypeParam) {
        return ResultGenerator.status(dictTypeService.updateById(id, DictTypeConvert.INSTANCE.convert(dictTypeParam)));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<DictTypePageVO>> getPageList(DictTypePageParam dictTypePageParam, PageQuery query){
        PagedResult<DictTypePageBO> dictTypePageBO = dictTypeService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(dictTypePageParam),
                        DictTypeConvert.INSTANCE.convert(dictTypePageParam));
        return ResultGenerator.success(DictTypeConvert.INSTANCE.convert(dictTypePageBO));
    }

}